/*
 * p3898.cpp
 *
 *  Created on: 2013-5-6
 *      Author: zy
 */
#include<cstdio>
#include<cstring>
const int INF = 1000000000;
const int maxn = 10005;
int pos[505], len[505], w[maxn], dp[maxn][505];
bool u[maxn][505];
char s1[1005], s2[maxn];
int main()
{
	while (scanf("%s%s", s1, s2) != EOF)
	{
		int l1 = strlen(s1);
		int l2 = strlen(s2);
		w[0] = 0;
		for (int i = 0; i < l2; i++)
			w[i + 1] = w[i] + s2[i] - 'a' + 1;
		memset(u, 0, sizeof(u));
		memset(len, 0, sizeof(len));
		int k = 0, l;
		for (int i = 0; i < l1; i++)
		{
			if (s1[i] != '*')
			{
				pos[k] = i;
				for (; i < l1 && s1[i] != '*'; i++, len[k]++)
					;
				k++;
			}
		}
		for (int i = 0; i < k; i++)
		{
			for (int j = 0; j < l2; j++)
			{
				for (l = 0; l < len[i] && j + l < l2; l++)
				{
					if (s1[pos[i] + l] != '?' && s1[pos[i] + l] != s2[j + l])
						break;
				}
				if (l == len[i])
					u[j][i] = true;
			}
		}
		for (int i = 0; i <= l2; i++)
			for (int j = 0; j <= k; j++)
				dp[i][j] = INF;
		dp[l2][0]=0;
		for (int i = l2 - 1; i >= 0; i--)
		{
			dp[i][0] = 0;
			for (int j = k; j > 0; j--)
			{
				if (dp[i + 1][j] != INF)
					dp[i][j] = dp[i + 1][j] + s2[i] - 'a' + 1;
				if (u[i][k - j])
				{
					if (i + len[k - j] <= l2 && dp[i][j] > dp[i + len[k - j]][j
							- 1] + w[i + len[k - j]] - w[i])
						dp[i][j] = dp[i + len[k - j]][j - 1]
								+ w[i + len[k - j]] - w[i];
				}
			}
		}
		int res = INF;
		for (int i = 0; i < l2; i++)
			if (res > dp[i][k])
				res = dp[i][k];
		if (res == INF)
			res = -1;
		printf("%d\n", res);
	}
}
